/*
 * This code implements stVSSIM VQA as suggested by Anush Moorthy and A.C Bovik
 * in "Efficient Motion Weighted Spatio-Temporal Video SSIM Index"
 * http://live.ece.utexas.edu/publications/2010/moorthy_spie_jan10.pdf
 *
 * Please cite the following paper in any published work if you use this software.
 * Anus K. Moorthy, Alan C. Bovik,"Efficient Motion Weighted Spatio-Temporal
 * Video SSIM Index", SPIE Conference on Human Vision and Electronic Imaging,
 * San Jose, CA, January 17-21, 2010
 *
 * File: vssim.h
 *
 * This module contains all the common structures and declarations used by the
 * application.
 */

#ifndef VSSIM_H_
#define VSSIM_H_

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"

//typedef long long unsigned int uint64_t;

typedef enum
{
	SUCCESS = 0,
	FAIL = 1
}vssim_result_t;

typedef enum
{
	FORMAT_YONLY = 0,
	FORMAT_YUV420 = 1,
	FORMAT_YUV422 = 2,
	FORMAT_YUV444 = 3,
}vssim_format_t;

typedef enum
{
	Y = 0,
	U = 1,
	V = 2
}vssim_ImgComp_t;

typedef struct
{
	int width;
	int height;
}vssim_size_t;

typedef struct
{
	float score_Y;
	float score_U;
	float score_V;
//	float FrScore;
}vssim_FrScore_t;

typedef struct
{
	int x;
	int y;
}vssim_mv_t;

typedef struct
{
	CvMat *H;
	CvMat *V;
	CvMat *L;
	CvMat *R;
}vssim_filters_t;

typedef struct
{
	IplImage *H;
	IplImage *V;
	IplImage *L;
	IplImage *R;
}vssim_FilStats_t;

typedef struct
{
	vssim_FilStats_t Mu;
	vssim_FilStats_t Sigma;
}vssim_ImgStats_t;

typedef struct
{
	vssim_size_t size;			// resolution of the input videos
	vssim_format_t format;		// format of the input videos
	int nframes;				// total number of frames in the shorter video
	vssim_FrScore_t *Sframe;
	vssim_FrScore_t *Tframe;
}vssim_global_t;

typedef struct
{
	char fileName[50];		// input filename
	FILE *fptr;				// input file pointer
	char *y;				// y data in the file
	char *u;				// u data in the file
	char *v;				// v data in the file
	IplImage *frame_y;		// Image storing the y data
	IplImage *frame_u;		// Image storing the u data
	IplImage *frame_v;		// Image storing the v data
	CvScalar mean;			// Mean of the frame
	CvScalar variance;		// Variance of the frame
}vssim_video_t;

#define HEIGHT_Y(global) ((global)->size.height)

#define HEIGHT_U(global)								\
(														\
	(FORMAT_YONLY == (global)->format) ? 0 :			\
	(FORMAT_YUV420 == (global)->format) ?				\
			((global)->size.height >> 2) :				\
	(FORMAT_YUV422 == (global)->format) ?				\
			((global)->size.height >> 1) :				\
			((global)->size.height)						\
)

#define HEIGHT_V(global) (HEIGHT_U(global))

#define FRAME_HEIGHT(global) (HEIGHT_Y(global) + HEIGHT_U(global) + HEIGHT_V(global))

#endif /* VSSIM_H_ */
